home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 29 / CDT29.iso / e-Mail / WorldClient Pro 2.2.3 / wcsetup.exe / WEBHELP.ZIP / treeview / SiblingChildTree.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-10-21  |  1.9 KB  |  191 lines

  1. package treeview;
  2.  
  3. public class SiblingChildTree {
  4.    protected SiblingChildTree parent = null;
  5.    protected SiblingChildTree sibling_left = null;
  6.    protected SiblingChildTree sibling_right = null;
  7.    protected SiblingChildTree child = null;
  8.  
  9.    public SiblingChildTree getChild() {
  10.       return this.child;
  11.    }
  12.  
  13.    public SiblingChildTree pruneThisSubtree() {
  14.       if (this.sibling_left != null) {
  15.          this.sibling_left.sibling_right = this.sibling_right;
  16.          if (this.sibling_right != null) {
  17.             this.sibling_right.sibling_left = this.sibling_left;
  18.          }
  19.       } else if (this.sibling_right != null) {
  20.          this.sibling_right.sibling_left = null;
  21.          if (this.parent != null) {
  22.             this.parent.child = this.sibling_right;
  23.          }
  24.       }
  25.  
  26.       SiblingChildTree var1;
  27.       for(var1 = this; var1.parent != null; var1 = var1.parent) {
  28.       }
  29.  
  30.       while(var1.sibling_left != null) {
  31.          var1 = var1.sibling_left;
  32.       }
  33.  
  34.       if (var1 == this) {
  35.          var1 = this.sibling_right;
  36.       }
  37.  
  38.       this.parent = null;
  39.       this.sibling_left = null;
  40.       this.sibling_right = null;
  41.       return var1;
  42.    }
  43.  
  44.    protected void setParent(SiblingChildTree var1) {
  45.       this.parent = var1;
  46.       if (this.sibling_right != null) {
  47.          this.sibling_right.setParent(var1);
  48.       }
  49.  
  50.    }
  51.  
  52.    public SiblingChildTree getParent() {
  53.       return this.parent;
  54.    }
  55.  
  56.    public SiblingChildTree nextNode() {
  57.       if (this.child != null) {
  58.          return this.child;
  59.       } else if (this.sibling_right != null) {
  60.          return this.sibling_right;
  61.       } else {
  62.          for(SiblingChildTree var1 = this.parent; var1 != null; var1 = var1.parent) {
  63.             if (var1.sibling_right != null) {
  64.                return var1.sibling_right;
  65.             }
  66.          }
  67.  
  68.          return null;
  69.       }
  70.    }
  71.  
  72.    public SiblingChildTree getSibling() {
  73.       return this.sibling_right;
  74.    }
  75.  
  76.    public SiblingChildTree prevNode() {
  77.       if (this.sibling_left == null) {
  78.          return this.parent != null ? this.lastBeforeMatch(this.parent) : null;
  79.       } else {
  80.          SiblingChildTree var1 = this.sibling_left.child;
  81.          if (var1 == null) {
  82.             return this.sibling_left;
  83.          } else {
  84.             while(var1.sibling_right != null) {
  85.                var1 = var1.sibling_right;
  86.             }
  87.  
  88.             return this.lastBeforeMatch(var1);
  89.          }
  90.       }
  91.    }
  92.  
  93.    private SiblingChildTree lastBeforeMatch(SiblingChildTree var1) {
  94.       SiblingChildTree var2 = null;
  95.  
  96.       do {
  97.          if (var2 != null) {
  98.             var1 = var2;
  99.          }
  100.  
  101.          var2 = var1.nextNode();
  102.       } while(var2 != this);
  103.  
  104.       return var1;
  105.    }
  106.  
  107.    public SiblingChildTree[] getChildren() {
  108.       SiblingChildTree[] var1 = new SiblingChildTree[this.numberOfChildren()];
  109.       SiblingChildTree var2 = this.child;
  110.  
  111.       for(int var3 = 0; var3 < var1.length; ++var3) {
  112.          var1[var3] = var2;
  113.          var2 = var2.sibling_right;
  114.       }
  115.  
  116.       return var1;
  117.    }
  118.  
  119.    public int numberOfChildren() {
  120.       int var1 = 0;
  121.  
  122.       for(SiblingChildTree var2 = this.child; var2 != null; var2 = var2.sibling_right) {
  123.          ++var1;
  124.       }
  125.  
  126.       return var1;
  127.    }
  128.  
  129.    public SiblingChildTree pruneChildren() {
  130.       if (this.child == null) {
  131.          return null;
  132.       } else {
  133.          this.child.setParent((SiblingChildTree)null);
  134.          SiblingChildTree var1 = this.child;
  135.          this.child = null;
  136.          return var1;
  137.       }
  138.    }
  139.  
  140.    public boolean isSibling(SiblingChildTree var1) {
  141.       if (this == var1) {
  142.          return false;
  143.       } else {
  144.          SiblingChildTree var2;
  145.          for(var2 = this; var2.sibling_left != null; var2 = var2.sibling_left) {
  146.          }
  147.  
  148.          while(var2 != null) {
  149.             if (var2 == var1) {
  150.                return true;
  151.             }
  152.  
  153.             var2 = var2.sibling_right;
  154.          }
  155.  
  156.          return false;
  157.       }
  158.    }
  159.  
  160.    public void addChild(SiblingChildTree var1) {
  161.       if (var1 == null) {
  162.          throw new IllegalArgumentException("SiblingChildTree.addChild(): child is a null reference");
  163.       } else if (this.child == null) {
  164.          this.child = var1;
  165.          var1.setParent(this);
  166.       } else {
  167.          this.child.addSibling(var1);
  168.       }
  169.    }
  170.  
  171.    public SiblingChildTree getSiblingLeft() {
  172.       return this.sibling_left;
  173.    }
  174.  
  175.    public void addSibling(SiblingChildTree var1) {
  176.       if (var1 == null) {
  177.          throw new IllegalArgumentException("SiblingChildTree.addSibling(): sibling is a null reference");
  178.       } else if (this.sibling_right == null) {
  179.          this.sibling_right = var1;
  180.          var1.sibling_left = this;
  181.          var1.setParent(this.parent);
  182.       } else {
  183.          SiblingChildTree var2;
  184.          for(var2 = this.sibling_right; var2.getSibling() != null; var2 = var2.getSibling()) {
  185.          }
  186.  
  187.          var2.addSibling(var1);
  188.       }
  189.    }
  190. }
  191.